class BooleanColumnsNotNull < ActiveRecord::Migration
  BOOLEAN_COLUMNS = {Forum => [:category, :private], Topic => [:sticky, :locked]}
  def self.up
    BOOLEAN_COLUMNS.each do |model_class, columns|
      columns.each do |column|
        change_column model_class.table_name, column, :boolean, :default => false, :null => false
        model_class.update_all("#{column}=0", "#{column} IS NULL")
      end
    end
  end

  def self.down
    BOOLEAN_COLUMNS.each do |table, columns|
      columns.each do |column|
        change_column table, column, :boolean, :null => true # unable to remove default unfortunately
      end
    end
  end
end
